<?php
namespace application\Comm;

class Request extends \library\Core\Comm\Request{

    public static $_POSTGET = [];

    public static function get($key,$name='') {
        if($name){
            return isset(self::$_POSTGET[$key][$name]) ? self::$_POSTGET[$key][$name] : null;
        }
        return isset(self::$_POSTGET[$key]) ? self::$_POSTGET[$key] : null;
    }
    
    /**
     * 搜索选项
     * @param string $key
     * @return array
     */
    public static function search($key){
        $condition = [];
        $dataProvider = isset($_GET[$key]) ? $_GET[$key] : [];
        foreach($dataProvider as $name=>$value){
            !empty($value) ? $condition[$name] = $value : null;
        }
        return $condition;
    }
    
    /**
     * 获取GET
     * @param string $name
     * @param string $key
     */
    public static function getParam($name, $key = '') {
        if ($key !== '') {
            return isset($_GET[$name][$key]) ? $_GET[$name][$key] :  null;
        }
        return isset($_GET[$name]) ? $_GET[$name] : null;        
    }
    
    /**
     * 获取POST
     * @param string $name
     * @param string $key
     */
    public static function postParam($name, $key = '') {
        if ($key !== '') {
            return isset($_POST[$name][$key]) ? $_POST[$name][$key] :  null;
        }
        return isset($_POST[$name]) ? $_POST[$name] : null;
    }

    public static function getParams()
    {
        return $_GET;
    }
}
